from fastapi import APIRouter, Request
from fastapi.responses import HTMLResponse
from fastapi.templating import Jinja2Templates
import os

# 创建API路由器
router_html_real = APIRouter()

# 定义模板目录
templates = Jinja2Templates(directory="static")

@router_html_real.get("/", response_class=HTMLResponse)
async def get_html_index(request: Request):
    """
    返回静态目录下的index.html页面
    """
    return templates.TemplateResponse("index.html", {"request": request})

@router_html_real.get("/{html_file}", response_class=HTMLResponse)
async def get_html_file(request: Request, html_file: str):
    """
    返回静态目录下的指定HTML文件
    """
    if not html_file.endswith(".html"):
        html_file += ".html"
    return templates.TemplateResponse(html_file, {"request": request}) 